package cn.xiyun.xiyuncc.service.impl;

import cn.xiyun.xiyuncc.service.ITokenService;
import cn.xiyun.xiyuncc.util.StrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class TokenServiceImpl implements ITokenService {

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;


    @Override
    public String createToken(String ids) {
    // 获取token
        // TODO 获取登陆人id
        Long loginId = 3L;
        //防重token获取
        String token = StrUtils.getRandomString(10);
        // 存入redis 10分钟有效
        redisTemplate.opsForValue().set(loginId+":"+ids,token,20, TimeUnit.MINUTES);
        return token;
    }
}


















